//
// Created by HP on 2025/11/14.
//

#ifndef FLIGHTSERVER_MODEL_H
#define FLIGHTSERVER_MODEL_H
#include <unordered_map>
#include <string>
#include <iostream>
#include <utility>
#include "../include/database.h"

class Model {
public:
    std::string TableName;
    std::string charset;
    std::unordered_map<std::string, std::string> TableCols;
    bool isBind = false;

    explicit Model(std::string name="models", std::string cset="utf8mb4") : TableName(std::move(name)), charset(std::move(cset)) {
        TableCols["id"]="INT PRIMARY KEY AUTO_INCREMENT";
    };
    void setTableDefault(const std::string& key, std::string value) ;

    virtual void bind(const std::string& key, const std::string& value) = 0;

    virtual bool save() = 0;

    void initDatabase() ;

    // SQL注入防护：转义SQL字符串字面量
    static std::string escapeSqlLiteral(const std::string& value);
};


#endif //FLIGHTSERVER_MODEL_H
